﻿using System.Collections.Generic;
using System.Threading.Tasks;

namespace Core.DataAccess.ApiJson.SearchService
{
    public interface ISearchProvider
    {

        #region Operation Index
        /// <summary>
        /// 创建索引
        /// </summary>
        /// <param name="indexSchema">索引的信息</param>
        /// <returns></returns>
        (bool IsSuccess, string Result) CreateIndex(string indexName, object indexSchema);

        /// <summary>
        /// 修改索引
        /// </summary>
        /// <param name="indexSchema">索引的信息</param>
        /// <returns></returns>
        (bool IsSuccess, string Result) ModifyIndex(string indexName, object indexSchema);

        /// <summary>
        /// 删除索引
        /// </summary>
        /// <param name="indexName"></param>
        /// <returns></returns>
        (bool IsSuccess, string Result) DeleteIndex(string indexName);

        /// <summary>
        /// 是否存在索引
        /// </summary>
        /// <param name="indexName"></param>
        /// <returns></returns>
        (bool IsSuccess, string Result) AnyIndex(string indexName);

        #endregion

        #region Operation Index Async
        /// <summary>
        /// 创建索引
        /// </summary>
        /// <param name="indexSchema">索引的信息</param>
        /// <returns></returns>
        Task<(bool IsSuccess, string Result)> CreateIndexAsync(string indexName, object indexSchema);

        /// <summary>
        /// 修改索引
        /// </summary>
        /// <param name="indexSchema">索引的信息</param>
        /// <returns></returns>
        Task<(bool IsSuccess, string Result)> ModifyIndexAsync(string indexName, object indexSchema);

        /// <summary>
        /// 删除索引
        /// </summary>
        /// <param name="indexName"></param>
        /// <returns></returns>
        Task<(bool IsSuccess, string Result)> DeleteIndexAsync(string indexName);

        /// <summary>
        /// 是否存在索引
        /// </summary>
        /// <param name="indexName"></param>
        /// <returns></returns>
        Task<(bool IsSuccess, string Result)> AnyIndexAsync(string indexName);
        #endregion



        #region Operation Data
        /// <summary>
        /// 创建索引数据
        /// </summary>
        /// <returns></returns>
        (bool IsSuccess, string Result) AddIndexData(string indexName, IndexData indexData);

        /// <summary>
        /// 修改索引数据
        /// </summary>
        /// <returns></returns>
        (bool IsSuccess, string Result) ModifyIndexData(string indexName, IndexData indexData);

        /// <summary>
        /// 删除索引数据
        /// </summary>
        /// <param name="indexName">索引名称</param>
        /// <param name="indexKey">索引关键字</param>
        /// <returns></returns>
        (bool IsSuccess, string Result) DeleteIndexData(string indexName, string indexKey);

        /// <summary>
        /// 批量添加索引数据
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="datas"></param>
        /// <returns></returns>
        (bool IsSuccess, string Result) BlukAdditionIndexDatas(string indexName, List<IndexData> datas);
        #endregion

        #region Operation Data Async
        /// <summary>
        /// 创建索引数据
        /// </summary>
        /// <returns></returns>
        Task<(bool IsSuccess, string Result)> AddIndexDataAsync(string indexName, IndexData indexData);

        /// <summary>
        /// 修改索引数据
        /// </summary>
        /// <returns></returns>
        Task<(bool IsSuccess, string Result)> ModifyIndexDataAsync(string indexName, IndexData indexData);

        /// <summary>
        /// 删除索引数据
        /// </summary>
        /// <param name="indexName">索引名称</param>
        /// <param name="indexKey">索引关键字</param>
        /// <returns></returns>
        Task<(bool IsSuccess, string Result)> DeleteIndexDataAsync(string indexName, string indexKey);

        /// <summary>
        /// 批量添加索引数据
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="datas"></param>
        /// <returns></returns>
        Task<(bool IsSuccess, string Result)> BlukAdditionIndexDatasAsync(string indexName, List<IndexData> datas);
        #endregion



        #region Search Data

        (bool IsSuccess, string Result) GetByKey(string indexName, string indexKey);
        Task<(bool IsSuccess, string Result)> GetByKeyAsync(string indexName, string indexKey);


        /// <summary>
        /// 正则搜索
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        object SearchOfRex(SearchPagination search);

        /// <summary>
        /// 模糊搜索，支持拼写容错
        /// 适用于：匹配搜索文章大量文本数据
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="field">查询字段</param>
        /// <param name="value">keyword</param>
        /// <param name="fuzziness">错词距离</param>
        /// <returns></returns>
        object SearchOfLikeContent(SearchPagination search, int fuzziness = 1);

        /// <summary>
        /// 通配符号
        /// 适用于：短小字符
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        object SearchOfWildcard(SearchPagination search);

        /// <summary>
        /// 根据距离范围搜索
        /// </summary>
        /// <returns></returns>
        object SearchOfLocation(SearchPagination search);

        /// <summary>
        /// 多条件And关系搜索
        /// </summary>
        /// <returns></returns>
        object SearchFieldsOfAuto(SearchPagination search, List<SearchCondition> conditions);

        /// <summary>
        /// 获取下一页根据关键字
        /// 搜索分两种： 1. 分页搜索（default）， 2.上拉继续加载. 这是第二种
        /// </summary>
        /// <param name="key">查询关键字</param>
        /// <param name="minute">Key有效时间</param>
        /// <returns></returns>
        object GetNextPageDataByPrevKey(string key, int minute);
        #endregion

        #region Search Data Async
        /// <summary>
        /// 正则搜索
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        Task<object> SearchOfRexAsync(SearchPagination search);

        /// <summary>
        /// 模糊搜索，支持拼写容错
        /// 适用于：匹配搜索文章大量文本数据
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="field">查询字段</param>
        /// <param name="value">keyword</param>
        /// <param name="fuzziness">错词距离</param>
        /// <returns></returns>
        Task<object> SearchOfLikeContentAsync(SearchPagination search, int fuzziness = 1);

        /// <summary>
        /// 通配符号
        /// 适用于：短小字符
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        Task<object> SearchOfWildcardAsync(SearchPagination search);

        /// <summary>
        /// 根据距离范围搜索
        /// </summary>
        /// <returns></returns>
        Task<object> SearchOfLocationAsync(SearchPagination search);

        /// <summary>
        /// 多条件And关系搜索
        /// </summary>
        /// <returns></returns>
        Task<object> SearchFieldsOfAutoAsync(SearchPagination search, List<SearchCondition> conditions);

        /// <summary>
        /// 获取下一页根据关键字
        /// 搜索分两种： 1. 分页搜索（default）， 2.上拉继续加载. 这是第二种
        /// </summary>
        /// <param name="key">查询关键字</param>
        /// <param name="minute">Key有效时间</param>
        /// <returns></returns>
        Task<object> GetNextPageDataByPrevKeyAsync(string key, int minute);
        #endregion

    }
}
